assume ds:data,cs:code,es:table,ss:stack

extrn copy_info:near,clear_screen:near,show_str:near,divdw:near,dtoc:near

data segment
        ;以下是表示21年的21个字符串
        db 	'1975','1976','1977','1978','1979','1980','1981','1982','1983'
        db	'1984','1985','1986','1987','1988','1989','1990','1991','1992'
        db 	'1993','1994','1995'
        
;以下是表示21年公司总收的21个dword型数据
        dd 	16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
        dd 	345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
        
;以下是表示21年公司雇员人数的21个word型数据
        dw 	3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
        dw 	11542,14430,45257,17800        
data ends

table segment
        db 21 dup('year summ ne ?? ')
table ends

data_sorted segment
    db 	10 	dup (0)
data_sorted ends

stack segment
	db	30 	dup (0)
stack ends

code segment
start: 

	mov	ax,data
	mov	ds,ax
	mov	ax,table
	mov	es,ax
	
	mov ax,stack
	mov ss,ax
	mov sp,30

    ; 复制到table数据段
	call copy_info							

    mov bx,0
	mov ax,data_sorted
    mov ds,ax
    mov si,0

    ; 清屏留出位置
	call clear_screen

    mov cx,21        
	mov dh,1
    ;dh表示要显示的行数

show_info: 
    push cx
	; 年份
    mov ax,es:[bx]
    mov ds:[si],ax
    mov ax,es:[bx+2]
    mov ds:[si+2], ax

    mov byte ptr ds:[si+4],0

	;第4列
    mov dl,4   								
    mov ch,0
    ;设置颜色，00000111b表示白底黑字这样才能看到
    mov cl,00000111b
    call show_str

    push dx;显示总收入
    mov ax,es:[bx+5]
    mov dx,es:[bx+7]  
    call dtoc
    pop dx            

    mov dl,14
    mov ch,0         
    mov cl,00000111b
    call show_str

    push dx
    mov ax,es:[bx+10]
    mov dx,0
    call dtoc
    pop dx

    mov dl,34
    mov ch,0
    mov cl,00000111b
    call show_str

    push dx
    mov ax,es:[bx+13]
    mov dx,0
    call dtoc
    pop dx

    mov dl,50
    mov ch,0          
    mov cl,00000111b
    call show_str

    add bx,16      
    add dh,1 
    pop cx 
    loop show_info
 
    mov ax,4c00H
    int 21H
	
code ends
end start
